import { UserVerifys } from './userVerify';
let _UserVerifys = UserVerifys;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import UserVerifyMock from './mk/mng/card/userVerifyMock';
 * UserVerifyMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mk/mng/card/userVerify/listKey').reply(config => {
      let params = config.params;
      let mockUserVerifys = _UserVerifys.filter(userVerify => {
      	if(params.cardId||params.cardId==''){ if( userVerify.cardId.indexOf(params.cardId)>=0) return true;}
      	if(params.userCardCode||params.userCardCode==''){ if( userVerify.userCardCode.indexOf(params.userCardCode)>=0) return true;}
      	if(params.consumeSource||params.consumeSource==''){ if( userVerify.consumeSource.indexOf(params.consumeSource)>=0) return true;}
      	if(params.locationName||params.locationName==''){ if( userVerify.locationName.indexOf(params.locationName)>=0) return true;}
      	if(params.staffOpenid||params.staffOpenid==''){ if( userVerify.staffOpenid.indexOf(params.staffOpenid)>=0) return true;}
      	if(params.verifyCode||params.verifyCode==''){ if( userVerify.verifyCode.indexOf(params.verifyCode)>=0) return true;}
      	if(params.remarkAmount||params.remarkAmount==''){ if( userVerify.remarkAmount.indexOf(params.remarkAmount)>=0) return true;}
      	if(params.outerStr||params.outerStr==''){ if( userVerify.outerStr.indexOf(params.outerStr)>=0) return true;}
      	if(params.createTime||params.createTime==''){ if( userVerify.createTime.indexOf(params.createTime)>=0) return true;}
      	if(params.id||params.id==''){ if( userVerify.id.indexOf(params.id)>=0) return true;}
      	if(params.userid||params.userid==''){ if( userVerify.userid.indexOf(params.userid)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockUserVerifys
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mk/mng/card/userVerify/list').reply(config => {
      let params = config.params;
      let mockUserVerifys = _UserVerifys.filter(userVerify => {
      	var isTrue=false;
      	if(params.cardId||params.cardId==''){if(userVerify.cardId.indexOf(params.cardId)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.userCardCode||params.userCardCode==''){if(userVerify.userCardCode.indexOf(params.userCardCode)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.consumeSource||params.consumeSource==''){if(userVerify.consumeSource.indexOf(params.consumeSource)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.locationName||params.locationName==''){if(userVerify.locationName.indexOf(params.locationName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.staffOpenid||params.staffOpenid==''){if(userVerify.staffOpenid.indexOf(params.staffOpenid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.verifyCode||params.verifyCode==''){if(userVerify.verifyCode.indexOf(params.verifyCode)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.remarkAmount||params.remarkAmount==''){if(userVerify.remarkAmount.indexOf(params.remarkAmount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.outerStr||params.outerStr==''){if(userVerify.outerStr.indexOf(params.outerStr)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createTime||params.createTime==''){if(userVerify.createTime.indexOf(params.createTime)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.id||params.id==''){if(userVerify.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.userid||params.userid==''){if(userVerify.userid.indexOf(params.userid)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockUserVerifys
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockUserVerifys.length;
      mockUserVerifys = mockUserVerifys.filter((userVerify, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockUserVerifys,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mk/mng/card/userVerify/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _UserVerifys = _UserVerifys.filter(userVerify => userVerify.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mk/mng/card/userVerify/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _UserVerifys = _UserVerifys.filter(userVerify => !params.includes(userVerify.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mk/mng/card/userVerify/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { cardId,userCardCode,consumeSource,locationName,staffOpenid,verifyCode,remarkAmount,outerStr,createTime,id,userid } = params;
      _UserVerifys.some(userVerify => {
        if (userVerify.id === id) {
			userVerify.cardId = cardId;
			userVerify.userCardCode = userCardCode;
			userVerify.consumeSource = consumeSource;
			userVerify.locationName = locationName;
			userVerify.staffOpenid = staffOpenid;
			userVerify.verifyCode = verifyCode;
			userVerify.remarkAmount = remarkAmount;
			userVerify.outerStr = outerStr;
			userVerify.createTime = createTime;
			userVerify.id = id;
			userVerify.userid = userid
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mk/mng/card/userVerify/add').reply(config => {
      var params = JSON.parse( config.data );
      let { cardId,userCardCode,consumeSource,locationName,staffOpenid,verifyCode,remarkAmount,outerStr,createTime,id,userid } = params;
      _UserVerifys.push({
		cardId:cardId,
		userCardCode:userCardCode,
		consumeSource:consumeSource,
		locationName:locationName,
		staffOpenid:staffOpenid,
		verifyCode:verifyCode,
		remarkAmount:remarkAmount,
		outerStr:outerStr,
		createTime:createTime,
		id:id,
		userid:userid
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};